package com.itheima.controller;

import com.itheima.common.PageResult;
import com.itheima.common.Result;
import com.itheima.entity.Brand;
import com.itheima.entity.SerachDto;
import com.itheima.service.BrandService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/findAll.do")
    public List<Brand> findAll(){
        return brandService.findAll();
    }

    @GetMapping("/findPage.do")
    public  PageResult findPageAll(int page, int size){
         return brandService.findPage(new SerachDto(),page,size);
    }

    @PostMapping("/findList.do")
    public List<Brand> findList(@RequestBody SerachDto serachDto){
        return brandService.fidnList(serachDto);
    }

    @PostMapping("/findPage.do")
    public PageResult findPage(@RequestBody SerachDto serachDto, int page, int size){
        return brandService.findPage(serachDto,page,size);
    }

    @GetMapping("/findById.do")
    public Brand findById(Integer id){
        return brandService.findById(id);
    }

    @PostMapping("/add.do")
    public Result add(@RequestBody Brand brand){
        return  brandService.add(brand);
    }

    @PostMapping("/update.do")
    public Result update(@RequestBody Brand brand){
        return brandService.updateBrand(brand);
    }

    @GetMapping("/delete.do")
    public Result delete(Integer id){
        return brandService.delete(id);
    }

}
